// 引入获取商品得请求方法
import * as api from "@/api"

export default{
    namespaced:true,
    state:{
        productData:[]
    },
    mutations:{
        SET_PRODUCT(state,payload){
            state.productData=payload
        },
        // 让库存减少
        DECREASE_INVENTORY(state,payload){
            console.log(payload)

            let target =state.productData.find(item=>item.id==payload)
            if(target){
                target.inventory--
            }
        }

    },
    actions:{
        async FETCH_PRODUCT(context,payload){
            let res=await api.fetchProduct()
            console.log(res)
            context.commit("SET_PRODUCT",res.data)
        }

    },
    getters:{},
    
}